package pais.www.stat;

import java.io.PrintWriter;
import java.util.StringTokenizer;

import pais.db.*;
import pasys.error.*;

class PrintUrlInfo {
  public static void printURL(PrintWriter toClient, StringTokenizer stok)  throws PaposException {
    int uid = 0;
    if (stok.hasMoreTokens()) {
      String UidOrUrl = stok.nextToken();
      try {
        uid = Integer.parseInt(UidOrUrl);
        printURL(toClient, uid);
      } catch (NumberFormatException e) {
        printURL(toClient, UidOrUrl);
      }
    } else {
      Commands.printStatUsage(toClient);
    }
  }

  private static void printURL(PrintWriter toClient, String url) throws PaposException {
    HtmlPage page =  HtmlPageTable.getInstance().getPage(url);
    if ( page == null ) {
      toClient.println("No such url => "+url);
    } else {
      PrintUrl.printURLSummary(toClient, page);
    }
  }

  private static void printURL(PrintWriter toClient, long uid) throws PaposException {
    HtmlPage page =  HtmlPageTable.getInstance().getPage(uid);
    if ( page == null ) {
      toClient.println("No such uid => "+uid);
    } else {
      PrintUrl.printURLSummary(toClient, page);
    }
  }



}
